
<template>
  <div >
      <basic-container  v-if="true" >
          <div style="height: 300px;text-align: center;">
              <div style="display: inline-block;margin-top: 130px;color: #b7b5b5;letter-spacing: 5px;">该功能待开发</div>
          </div>
      </basic-container>
      <basic-container v-else>
        <el-form ref="formSearch" :model="formSearch" label-width="100px" size="small" :inline="true">
            <el-form-item>
                <el-button  @click="handleExport">导出</el-button>
            </el-form-item>
            <el-form-item label="样品分类:">
                <el-select v-model="formSearch.type" placeholder="样品分类" style="width:100px">
                    <el-option label="全部" :value="0"></el-option>
                    <el-option label="未留样" :value="1"></el-option>
                    <el-option label="已留样" :value="2"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="检测项目:">
                <el-select v-model="formSearch.sbname" placeholder="检测项目" style="width:100px">
                    <el-option label="全部" :value="0"></el-option>
                    <el-option label="待处理" :value="1"></el-option>
                    <el-option label="已处理" :value="2"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="设备分类:">
                <el-select v-model="formSearch.classification" placeholder="设备分类" style="width:100px">
                    <el-option label="全部" :value="0"></el-option>
                    <el-option label="待处理" :value="1"></el-option>
                    <el-option label="已处理" :value="2"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="存放位置:">
                <el-select v-model="formSearch.location" placeholder="存放位置" style="width:100px">
                    <el-option label="全部" :value="0"></el-option>
                    <el-option label="待处理" :value="1"></el-option>
                    <el-option label="已处理" :value="2"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-input v-model="formSearch.sn" placeholder="请输入样品编码/名称、留样人"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="searchFormSubmit">搜索</el-button>
            </el-form-item>
            <el-form-item>
                <el-button @click="handleReset">重置</el-button>
            </el-form-item>
        </el-form>
        <!-- 表格 -->
        <avue-crud :option="tableOption"
                   :data="tableData"
                   :table-loading="tableLoading"
                   :page="page" ref="crud"
                   @current-change='currentPage'
                   @selection-change='selectionChange'
        >
            <template slot-scope="scope" slot="type">{{ scope.row. sampleType }}样本类型</template>
            <template slot-scope="scope" slot="handleTime">{{ scope.row.status==1?'未留样':'已留样' }}</template>
            <template slot-scope="scope" slot="status">{{ scope.row.status==1?'未留样':'已留样' }}</template>
            <template slot-scope="scope" slot="editTime">{{ scope.row.name }} <span>-</span> {{ scope.row.state }}</template>
        </avue-crud>
    </basic-container>
  </div>
</template>

<script>
import excel from '@/util/excel'
import { listOption } from "@/const-personal/sample/deviceFile.js"
import { getSampleList } from '@/api/sample/sampleList'

export default {
    name: "SampleEquipment",
    data() {
    return {
        formSearch: {
            type: '',
            sbname: '',
            classification: '',
            location: '',
            sn: '',
        },
        tableOption: listOption,
        page: {
            total: 10, // 总页数
            currentPage: 1, // 当前页数
            pageSize: 10, // 每页显示多少条
            pageSizes: [10]
        },
        tableLoading: false,
        tableData: [{ id: 0, status: 2, name: 'h哈哈' }, { id: 2, status: 1, name: 'h哈哈' }], // 数据
        sampleType: [{ id: 1, name: "lei1" }, { id: 2, name: "lei1" }], // 样品分类
        tableSelectedIds: [], //选中id
    }
    },
    methods: {
        // 搜索
        searchFormSubmit () {
            const data = {
                page : this.page.currentPage,
                size : this.page.pageSize,
                sample: {
                    startTime: moment(this.formSearch.date[0]).format('YYYY-MMM-DD'),
                    endTime: moment(this.formSearch.date[1]).format('YYYY-MMM-DD'),
                    sampleTypeId: 0,
                    name: this.formSearch.name,
                    entrustUnit: this.formSearch.entrustUnit,
                    client: this.formSearch.client
                }
            }
        },
        // 重置
        handleReset () {},
        // 切换页面
        currentPage (val) {
            console.log(val)
        },
        // 导出
        handleExport (){
          let selectedTabDatas = this.tableSelectedIds;
          if (selectedTabDatas.length > 0) {
            let filterTabDatas = [];
            selectedTabDatas.forEach(item => {
              let data = this.tableData.find(itm => {
                return item === itm.id
              })
              if (data) filterTabDatas.push(data)
            })
            const params = {
              title: ['序号', '样品分类', '样品编码', '样品名称','检测编码','检测项目','检测结果','设备类别','设备编码','设备名称','型号','品牌','存放位置','时间'],
              key: ['id', 'name', 'phone', 'date'],
              data: filterTabDatas,
              autoWidth: true,
              filename: '设备转入数据'
            }
            excel.export_array_to_excel(params)
          } else {
            this.$message({
              type: 'info',
              message: '请选择要导出的数据'
            });
          }
        },
        // 多选
        selectionChange (selection) {
            console.log(selection)
            this.tableSelectedIds = selection.map(item => item.id);
            // console.log(this.tableSelectedIds)
            console.log(selection)
        },
        // 获取全部table数据
        getTableList () {
            let data={
                page : this.page.currentPage,
                size : this.page.pageSize,
                sample: {}
            }
            console.log(data)
            getSampleList(data).then(res => {
                if(res.data.code==200){
                    this.tableData = res.data.data.list
                    this.page.total = res.data.data.total
                    this.page.currentPage = res.data.data.pageNum
                    this.page.pageSize = res.data.data.pageSize
                } else {
                    this.$notify.error({ title: '查询失败', message: '获取列表失败！', type: 'danger', })
                }
            })
        }
    },
    mounted() {
        this.getTableList()
    }
}
</script>

<style scoped></style>